<?php


namespace App\Extensions\Column;

use Encore\Admin\Grid\Displayers\AbstractDisplayer;

class Download extends AbstractDisplayer
{
    public function display($callback = '', $name = '')
    {
        if (!$callback) {
            return $this->value;
        } elseif ($callback instanceof \Closure) {
            $callback = $callback->bindTo($this->row);
            $href = call_user_func_array($callback, [$this->row]);
        } else {
            $href = $callback;
        }
        $name = $name ?: $this->value;
        return sprintf('<a href="%s" download="下载" target="_blank">%s</a>', $href, $name);
    }
}
